package de.baumann.browser.api.net.util

import de.baumann.browser.api.net.LicenceApiService
import de.baumann.browser.api.net.base.ApiBuilder
import de.baumann.browser.api.net.base.RxUtils
import de.baumann.browser.api.net.vo.*
import de.baumann.browser.rx.RxSchedulers
import io.reactivex.Observable

class LicenceHttpUtil {

    companion object {
        private val licenceApiService = ApiBuilder.buildService(LicenceApiService::class.java)
        fun licences(): Observable<Result<List<Licence>>> {
            return licenceApiService.licences()
        }

        /**
         * 激活 licence
         *
         * @param token     用户token
         * @param licenceId licenceId
         * @return Observable
         */
        fun licenceActive(licenceId: String): Observable<Result<Any>> {
            return licenceApiService.licenceActive(licenceId)
        }

        /**
         * licence 转赠
         *
         * [token]     用户token
         * [licenceId]  licenceId
         * [loginName] 接收人的用户名
         * @return Observable
         */
        fun licenceGives(licenceId: String, loginName: String): Observable<Result<Any>> {
            return licenceApiService.licenceGift(licenceId, loginName)
        }

        fun odinAddresss(address: String): Observable<Result<String>> {
            return licenceApiService.getTransOdinAddress(address)
        }

        fun getTransThorAddress(odinAddress: String,
                                thorAddress: String,
                                remark: String,
                                remark1: String,
                                remark2: String,
                                remark3: String,
                                remark4: String,
                                remark5: String): Observable<Result<Any>> {
            return licenceApiService.getTransAddress(odinAddress, thorAddress, remark, remark1, remark2, remark3, remark4, remark5)
        }

        /**
         * 转赠 记录
         *
         * @return Observable
         */
        fun transList(): Observable<Result<List<Transfer>>> {
            return licenceApiService.transList()
        }

        /**
         * 领免费licence
         */
        fun getFreeLicence(): Observable<Result<LoginInfo>> {
            return licenceApiService.getFreeLicence()
        }

        /**
         *获取licence状态
         * [licence] licence
         */
        fun getLicenceStatus(licence: String): Observable<Result<LoginInfo>> {
            return licenceApiService.getLicenceStatus(licence)
        }

        fun getLicenceCount(): Observable<Result<UseableCount>> {
            return licenceApiService.getLicenceCount()
        }


        fun getRank(): Observable<Result<List<Rank>>> {
            return licenceApiService.getRank()
        }
    }
}